<template>
  <div class="pointsRule">
    <el-card class="avue_height">
      <el-button type="primary" @click="addLevel" style="margin-bottom:20px">新增积分规则</el-button>
      <avue-crud
        ref="crud"
        style="width:100%"
        :data="loadData"
        :option="tableOption"
        :table-loading="loading"
      >
        <template slot-scope="scope" slot="indexLabel">
          <span>{{scope.row.$index+(page.current - 1) * page.size + 1}}</span>
        </template>
        <template slot-scope="scope" slot="time">
          <span>{{(scope.row.beginTime || scope.row.endTime)?scope.row.beginTime +' - '+scope.row.endTime:'永久'}}</span>
        </template>
        <template slot="menu" slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.row)">编辑</el-button>
          <el-button
            type="text"
            @click="switchs(scope.row)"
            :icon="scope.row.isenabled == '01'?'el-icon-circle-close':'el-icon-circle-check'"
          >{{scope.row.isenabled == '01'?'停用':'启用'}}</el-button>
          <el-button type="text" icon="el-icon-delete" @click="del(scope.row)">删除</el-button>
        </template>
      </avue-crud>
      <template>
        <div style="width:100%;position:relative;height:50px">
          <el-pagination
            :page-sizes="[10, 20,30,40, 50, 100]"
            :pager-count="7"
            :current-page="page.current"
            :page-size="page.size"
            :total="page.total"
            layout="total, sizes, prev, pager, next, jumper"
            style="margin:2% 0;position:absolute;right:1%"
            background
            @size-change="sizeChange"
            @current-change="currentChange"
          ></el-pagination>
        </div>
      </template>
    </el-card>
    <el-dialog
      :title="dialogTitle==1?'新增积分规则':'编辑积分规则'"
      destroy-on-close
      :visible.sync="dialogVisible"
      width="45%"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="120px"
        class="demo-ruleForm"
      >
        <el-form-item label="规则名称：" prop="integralRuleName">
          <el-input
            v-model="ruleForm.integralRuleName"
            placeholder="请输入规则名称，不超过30个字"
            :maxlength="30"
          ></el-input>
        </el-form-item>
        <el-form-item label="积分类型：" prop="integralRuleType">
          <el-select v-model="ruleForm.integralRuleType" placeholder="请选择积分类型" style="width:100%">
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in jflxList"
              :key="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="积分比例：" prop="integralRuleProportion">
          <span style="padding:0px 5px">用户消费1元，可得</span>
          <el-input-number
            v-model="ruleForm.integralRuleProportion"
            :min="0"
            :step="1"
            controls-position="right"
            style="width:58%"
            step-strictly
          ></el-input-number>
          <span style="padding:0px 5px">积分。</span>
        </el-form-item>
        <el-form-item label="渠道类型：" prop="integralChannelType">
          <el-select
            v-model="ruleForm.integralChannelType"
            placeholder="请选择渠道类型"
            style="width:100%"
          >
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in qdlxList"
              :key="item.value"
            ></el-option>
          </el-select>
          <!-- <el-checkbox-group v-model="ruleForm.integralChannelType">
            <el-checkbox
              :label="item.value"
              v-for="item in qdlxList"
              :key="item.value"
            >{{item.label}}</el-checkbox>
          </el-checkbox-group>-->
        </el-form-item>
        <el-form-item label="规则有效期：" required>
          <el-col :span="24">
            <el-form-item prop="gzyxq">
              <el-select
                v-model="ruleForm.gzyxq"
                placeholder="请选择规则有效期"
                style="width:100%"
                @change="gzyxqChange"
              >
                <el-option
                  :label="item.label"
                  :value="item.value"
                  v-for="item in gzyxqList"
                  :key="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="gzyxqShow">
            <el-form-item prop="gzyxqsj">
              <el-date-picker
                v-model="ruleForm.gzyxqsj"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                style="width:100%"
                @change="gzyxqsjChange"
                :default-time="['00:00:00', '23:59:59']"
              >></el-date-picker>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="积分规则说明：" prop="integralRuleExplain">
          <el-input
            v-model="ruleForm.integralRuleExplain"
            placeholder="请输入积分规则，不超过100个字"
            :maxlength="100"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态：" prop="isenabled">
          <el-radio-group v-model="ruleForm.isenabled">
            <el-radio label="01">启用</el-radio>
            <el-radio label="00">停用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handlClose">取 消</el-button>
        <el-button type="primary" @click="handlSure" :loading="loadingSure" v-if="dialogTitle">保 存</el-button>
        <el-button type="primary" @click="handlUpdate" :loading="loadingSure" v-else>修 改</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script src="./index.js"></script>
<style lang="scss" scoped>
</style>